# This is a sample Python script.
import requests
# Press Alt+Shift+X to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.


from binance.client import Client

# proxies = {
#     'http': 'http://127.0.0.1:10011',  # HTTP 代理
#     'https': 'https://127.0.0.1:10011'
# }

proxies = {
    'http': 'socks5://127.0.0.1:10010',
    'https': 'socks5://127.0.0.1:10010',
}

apiKey = "ZtrfFQwYrPs7qyZlsEgP1tIPwwEX0GAyyLRHI0bQ2oOvOmMZjGs9SSHTy8MEko6Y"
secrets = "GGuSQdyuU33r3q3EPZ3TXVmASd1sr0chlskeO7e96iP5hQx11lT4MWb76UqOjc39"

client = Client(requests_params={'proxies': proxies, 'timeout': 10},api_key=apiKey,api_secret=secrets)
print("connected")
# klines = client.get_klines(symbol='BTCUSDT', interval='1h', limit=100)
#
# for kline in klines:
#     print(kline)

info = client.get_account(omitZeroBalances="true")
print(info)
status = client.get_account_status()
print(status)
# status = client.get_account_api_trading_status()
# print(status)
# fees = client.get_trade_fee(symbol='BNBBTC')
# print(fees)
# account_info  = client.futures_account()
# print(account_info)
positions = client.futures_position_information()
print(positions)

# account_info = client.futures_account()
# positions = account_info['positions']
#
# for pos in positions:
#     if float(pos['positionAmt']) != 0:
#         print(f"Symbol: {pos['symbol']}, Position: {pos['positionAmt']}, Entry Price: {pos['entryPrice']}")

# 获取所有未成交的挂单
# open_orders = client.futures_get_open_orders()
# for order in open_orders:
#     print(f"""
#     交易对: {order['symbol']}
#     订单ID: {order['orderId']}
#     方向: {order['side']} ({order['positionSide']})  # BUY/SELL + LONG/SHORT
#     类型: {order['type']}  # LIMIT, MARKET, STOP_MARKET 等
#     价格: {order['price']}
#     数量: {order['origQty']}
#     状态: {order['status']}  # NEW（未成交）
#     """)

# 查询 U 本位永续合约的历史资金费率（最近 10 条）
# historical_rates = client.futures_funding_rate(symbol="BTCUSDT", limit=10)
# for rate in historical_rates:
#     print(f"时间: {rate['fundingTime']}, 费率: {rate['fundingRate']}")

all_funding_rates = client.futures_funding_rate()
# 遍历并打印非零费率的数据
for rate in all_funding_rates:
    if float(rate['fundingRate']) != 0:  # 过滤费率为 0 的交易对
        print(f"币种: {rate['symbol']}, 资金费率: {float(rate['fundingRate']) * 100:.4f}%")

# oc = client.get_current_order_count()
# print(oc)
# url = "https://api.binance.com/api/v3/klines"
# params = {
#     'symbol': 'BTCUSDT',
#     'interval': '1h',
#     'limit': 10
# }
#
# response = requests.get(url, params=params, proxies=proxies, timeout=10)
# data = response.json()
#
# for kline in data:
#     print(kline)